package	hottargui.config;

import hottargui.framework.*;

import java.util.*;
import hottargui.standard.*;

/** AlphaGame implementation.
    Presently simply a temporary test stub to be expanded
    by a test-driven process.
 */

public class AlphaGame implements Game {

	TarguiState currentState;
	TarguiFactory factory;
	GameObjectServer objectServer;
	
  public AlphaGame(AlphaTarguiFactory alphafactory) {
	  factory = alphafactory;
	  objectServer = factory.getGameObjectServer();
	  
	  // initialize state
	  currentState = factory.getNewGameState(this);
  }

  public TarguiFactory getFactory()
  {
	  return factory;
  }
  
  public void newGame() {
	  currentState.newGame();
  }

  /** return a specific tile */
  // TODO This might have possibilities for optimizations...
  public Tile getTile( Position p ) {
	  List<Tile> boardConf = objectServer.getGameData().getBoardConfiguration();
      for (Tile tile : boardConf)
      {
	  if (tile.getPosition().equals(p)) { return tile; }
      }   
      return null;
  }

  public Player getPlayerInTurn() {
    return null;
  }

  public State getState() {
    return currentState.getState();
  }
  private boolean moveIsValid(Position from, Position to)
  {
	  boolean rowOk, colOK;
	  if((from.getRow() - to.getRow() == 1) || (from.getRow() - to.getRow() == -1))
		  rowOk = true;
	  else
		  rowOk = false;
	  
	  if((from.getColumn() - to.getColumn() == 1) || (from.getColumn() - to.getColumn() == -1))
		  colOK = true;
	  else
		  colOK = false;
	  
	  return rowOk & colOK;
  }
  
  public boolean move(Position from, Position to, int count) {
	  return currentState.move(from, to, count);
  }

  public boolean buy(int count, Position deploy) {
	  return currentState.buy(count, deploy);
  }

  public PlayerColor turnCard() {
    return currentState.turnCard();
  }

  public void rollDie() {
  }

  public int getDieValue() {
    return 1;
  }
  
  public void setState(TarguiState newState)
  {
	  this.currentState = newState;
  }
  
  public Iterator<Tile> getBoardIterator() {
    return null;
  }

  public void addGameListener( GameListener observer ) {
  }

  public void report(String s) {
  }

	@Override
	public GameObjectServer getGameObjectServer() {
		return objectServer;
	}
}

